package com.jianyun.jyzs.widget;

import android.app.ActivityManager;
import android.app.NotificationManager;
import android.content.ComponentName;
import android.content.Context;


import java.util.List;

import static android.content.Context.ACTIVITY_SERVICE;

/**
 * Created by liml on 17/7/6.
 */

public class NotificationHandler {
    private final NotificationManager nm;
    private Context context;

    private NotificationHandler(Context context) {
        this.context = context;
        nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    }

    private static class SingleTonHandler {
        private static NotificationHandler getNotification(Context context) {
            return new NotificationHandler(context);
        }
    }

    public static NotificationHandler getInstance(Context context) {
        return SingleTonHandler.getNotification(context);
    }

    /**
     * TODO 待完成
     * @param title
     * @param msg
     */
    public void showNotification(String title, String msg) {
        /*ComponentName topActivity = getTopActivity(context);
        PendingIntent contentIntent = null;
        contentIntent = PendingIntent.getActivity(context,
                (int) SystemClock.uptimeMillis(),
                new Intent(context, SplashActivity.class),
                PendingIntent.FLAG_UPDATE_CURRENT);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.rce_ic_logo)   //设置图标
                .setAutoCancel(true)//消息点击后自动消息
                .setContentTitle(title)
                .setContentText(msg)
                .setDefaults(Notification.DEFAULT_SOUND)
                .setContentIntent(contentIntent);
        nm.notify(1, mBuilder.build());*/
    }

    public static ComponentName getTopActivity(Context context) {
        ActivityManager manager = (ActivityManager) context.getSystemService(ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> runningTaskInfos = manager.getRunningTasks(1);
        if (runningTaskInfos != null) {
            return runningTaskInfos.get(0).topActivity;
        } else {
            return null;
        }

    }
}
